import pygame

class player1(pygame.sprite.Sprite):
    # 生命值 暂时不实现
    health = 5
    armor = 1
    def __init__(self, bg_size):

        pygame.sprite.Sprite.__init__(self)

        self.image1 = pygame.transform.scale(pygame.image.load('../images/wugui.png').convert_alpha(),(54,54))
        self.active = True

        self.rect = self.image1.get_rect()
        self.width, self.height = bg_size[0], bg_size[1]
        self.rect.left, self.rect.top = (self.width - self.rect.width) -1000, self.height // 2
        self.speed = 5
        self.mask = pygame.mask.from_surface(self.image1)
        self.invincible = False
        # 生命值
        self.health = player1.health
        # 护甲值
        self.armor = player1.armor



    def moveUp(self):
        if self.rect.top > 0:
            self.rect.top -= self.speed
        else:
            self.rect.top = 0

    def moveDown(self):
        if self.rect.bottom < self.height:
            self.rect.top += self.speed
        else:
            self.rect.bottom = self.height

    def moveLeft(self):
        if self.rect.left > 0:
            self.rect.left -= self.speed
        else:
            self.rect.left = 0

    def moveRight(self):
        if self.rect.right < self.width:
            self.rect.left += self.speed
        else:
            self.rect.right = self.width

    def reset(self):
        self.rect.left, self.rect.top = (self.width - self.rect.width) -1000, self.height // 2
        self.active = True
        self.invincible = True


class player2(pygame.sprite.Sprite):
    # 生命值 暂时不实现
    health = 5
    armor = 1

    def __init__(self, bg_size):

        pygame.sprite.Sprite.__init__(self)

        self.image1 = pygame.transform.scale(pygame.image.load('../images/pangxie.png').convert_alpha(), (54,54))
        self.active = True

        self.rect = self.image1.get_rect()
        self.width, self.height = bg_size[0], bg_size[1]
        self.rect.left, self.rect.top = (self.width - self.rect.width) -150, self.height //2
        self.speed = 5
        self.mask = pygame.mask.from_surface(self.image1)
        self.invincible = False
        # 生命值
        self.health = player2.health
        # 护甲值
        self.armor = player2.armor

    def moveUp(self):
        if self.rect.top > 0:
            self.rect.top -= self.speed
        else:
            self.rect.top = 0

    def moveDown(self):
        if self.rect.bottom < self.height:
            self.rect.top += self.speed
        else:
            self.rect.bottom = self.height

    def moveLeft(self):
        if self.rect.left > 0:
            self.rect.left -= self.speed
        else:
            self.rect.left = 0

    def moveRight(self):
        if self.rect.right < self.width:
            self.rect.left += self.speed
        else:
            self.rect.right = self.width

    def reset(self):
        self.rect.left, self.rect.top = (self.width - self.rect.width) -150, self.height //2
        self.active = True
        self.invincible = True